package com.gimi.cloud.jimi.dao.dao.sys;

import com.gimi.cloud.jimi.dao.common.SqlProvider;
import com.gimi.cloud.jimi.dao.myMapper.MyMapper;
import com.gimi.cloud.jimi.dto.sys.SysRoleDTO;
import com.gimi.cloud.jimi.entity.sys.SysRoleEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

/**
 * Created by shazhiwei on 2017/12/15.
 */
public interface SysRoleDao extends MyMapper<SysRoleEntity>,BaseDao<SysRoleEntity,SysRoleDTO>{

    @Select("SELECT ro_id,ro_name,ro_alias FROM sys_role WHERE is_delete = 0;")
    List<SysRoleDTO> getRoleList();

    @Select("SELECT ro_id,ro_name,ro_alias FROM sys_role WHERE is_delete = 0 AND ro_id = #{roleId};")
    SysRoleDTO selectById(@Param(value = "roleId") Integer roleId);

    @SelectProvider(method = "sql",type = SqlProvider.class)
    List<SysRoleDTO> queryPage(String sql);

    @Select("SELECT count(1) FROM sys_role;")
    Long getCount();

    @Select("SELECT r.ro_id,r.ro_name,r.ro_alias,r.ro_description FROM sys_master_role mr LEFT JOIN sys_role r ON mr.ro_id = r.ro_id WHERE mr.is_delete = 0 AND r.is_delete = 0 AND mr.ma_id = #{maId};")
    List<SysRoleDTO> getRoleListByMasterId(@Param(value = "maId") Integer maId);
}
